<?php session_start();
require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Usuario.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/Gui/Fachada.php');


$fachada = new Fachada();
$repositorio = new RepositorioUsuario();
$_SESSION['enquete'] = $fachada->enqueteAtual();

$login = $_POST['login'];
$senha = md5($_POST['senha']);




if(!$_POST['login']=='' || !$_POST['senha']=='') {
    if(!$fachada->fazerLogin($login, $senha)) {
        $errologin=1;

    }
    else {
        $usuario = new Usuario();
        $usuario = $fachada->localizarUsuario($codigo, $nome, $login);
        $_SESSION['login'] =  $usuario->getLogin();
        $_SESSION['privilegio']= $usuario->getPrivilegio();
        $errologin=0;

    }
}      
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/Esquina_da_TI/default.css" rel="stylesheet" type="text/css" media="screen" />
        
        <script src="/Esquina_da_TI/js/tituloDinamico.js" type="text/javascript"></script>
       
        <title>Efetue o Login</title>
    </head>
    <body>
        <center>            
            <!--CABEÇALHO-->
            <div id="header">

                <div id="menu">
                    <ul id="main">
                         <li><a href="../index.php"><img src="/Esquina_da_TI/images/home.png" class="menu"  title="Inicio" /><br/><b>Inicio</b></a></li>
                    <li><a href="#"><img src="/Esquina_da_TI/images/forum.png" class="menu" title="Fórum"/><br/><b>Fórum</b></a></li>
                    <li><a href="#"><img src="/Esquina_da_TI/images/noticia.png" class="menu" title="Noticia"/><br/><b>Notícias</b></a></li>
                    <li><a href="#"><img src="/Esquina_da_TI/images/artigo.png" class="menu" title="Artigos"/><br/><b>Artigos</b></a></li>
                    <li><a href="/Esquina_da_TI/Gui/Downloads.php"><img src="/Esquina_da_TI/images/download.png" class="menu" title="Downloads"/><br/><b>Downloads</b></a></li>
                    <li><a href="/Esquina_da_TI/Gui/CadastroUsuario.php"><img src="/Esquina_da_TI/images/Cadastro.png" class="menu" title="Cadastro"/><br/><b>Cadastro</b></a></li>
                    <li><a href="javascript:exibirOportunidadeEmprego()"><img src="/Esquina_da_TI/images/oportunidade.png" class="menu" title="Empregos"/><br/><b>Empregabilidade</b></a></li>
                    <li><a href="javascript:exibirFaleConosco()"><img src="/Esquina_da_TI/images/faleconosco.png" class="menu" title="Fale Conosco"/><br/><b>Fale Conosco</b></a></li>
                    <li><a href="javascript:favoritos()"><img src="/Esquina_da_TI/images/addFavoritos.png" class="menu" title="Add Favoritos"/><br/><b>Favoritos</b></a></li>
                    </ul>
                </div>
                <div id="logo">

                    <marquee scrollamount="10" direction="left">
                        <form name="y_datetime">
                            <input name="textbox1" type=text class="style1" disabled="true" style="text-align:center;font-weight:bold" size=55 width=32 />
                        </form>
                    </marquee>


                    <!-- EXIBINDO O A DATA E A HORA NA TELA PRINCIPAL-->
                    <script language="javascript">

                        ydate = new Object();
                        ydate.style  = 3;
                        ydate.military = 0;

                        ydate.days1  = new Array("Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado");
                        ydate.days2  = new Array("Domingo","Segunda","Terça","Quarta",
                        "Quinta","Sexta","Sabado");
                        ydate.months1 = new Array("janeiro","fevereiro","março","abril","maio","junho","julho", "agosto","setembro","outubro","novembro","dezembro");
                        ydate.months2 = new Array("jan","fev","mar","abr","mai","jun",
                        "jul","ago","set","out","nov","dez");

                        function datedisplay() {

                            ydate.now   = new Date();
                            ydate.year  = ydate.now.getFullYear();
                            ydate.month = ydate.now.getMonth();
                            ydate.date  = ydate.now.getDate();
                            ydate.day   = ydate.now.getDay();
                            ydate.hour  = ydate.now.getHours();
                            ydate.min   = ydate.now.getMinutes();
                            ydate.sec   = ydate.now.getSeconds();
                            ydate.ampm  = "";

                            if (ydate.military) {
                                if (ydate.hour < 10) { ydate.hour = "0" + ydate.hour; }
                            }
                            else if (ydate.hour > 11) {
                                ydate.ampm = "Pm";
                                ydate.hour = ydate.hour - 12;
                            }
                            else { ydate.ampm = "Am"; }

                            if (ydate.hour == 0) { ydate.hour = 12; }
                            if (ydate.min < 10)  { ydate.min = "0" + ydate.min; }
                            if (ydate.sec < 10)  { ydate.sec = "0" + ydate.sec; }

                            if (ydate.style == 0)      { ydate.txt = ydate.months2[ydate.month]+" "+ydate.date+" "+ydate.year; }
                            else if (ydate.style == 1) { ydate.txt =":: "+ ydate.days2[ydate.day]+" "+ydate.hour+":"+ydate.min+":"+ydate.sec+" "+ydate.ampm+" ::"; }
                            else if (ydate.style == 2) { ydate.txt =":: "+ydate.date+" "+ydate.months2[ydate.month]+"  "+ydate.year+" :: "+ydate.hour+":"+ydate.min+":"+ydate.sec+" "+ydate.ampm+" ::"; }
                            else if (ydate.style == 3) { ydate.txt =":: "+ydate.days1[ydate.day]+" - "+ydate.date+" de " +ydate.months1[ydate.month]+" de "+ydate.year+" - "+ydate.hour+":"+ydate.min+":"+ydate.sec+" "+ydate.ampm+" ::"; }
                            else if (ydate.style == 4) { ydate.txt = ":: "+ydate.date+"/"+(ydate.month+1)+"/"+ydate.year+" :: "+ydate.hour+":"+ydate.min+":"+ydate.sec+" "+ydate.ampm+" ::"; }
                            else{ ydate.txt = ydate.year+"/"+(ydate.month+1)+"/"+ydate.date+" , "+ydate.hour+":"+ydate.min+":"+ydate.sec+" "+ydate.ampm; }

                            document.y_datetime.textbox1.value = ydate.txt;
                            ydate.id=setTimeout("datedisplay()",1000);
                        }

                        datedisplay();
                    </script>

                    <h1><a href="#"><span>Esquina da T.I.</span></a></h1>
                    <p>a Tecnologia a seu alcance</p>


                </div>
            </div>

            <!--CONTEUDO DA PAGINA-->
            <div id="wrapper">
                <div id="page">
                    <div align="center" style="border:double">
                        <br>
                        <br>
                        <br>
                        <div id="loginCenter" class="sidebar">

                    <ul>
                        <li>
                            <h2>Efetue seu Login</h2>
                            <?php

                            if (isset ($_SESSION['login'])) {
                               echo "<script>top.location.href='Forum.php';</script>";
                            }else {
                                echo " <div id='login'>";

                                echo"<form  method='POST' action='' >";
                                echo" <table border='0' align='center'>";
                                echo"<tr>";
                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                echo " <font size='1px'><br>Login: <input type='text' name='login' value='' size='28' style='height:20px;font-size:10px' />
                                        <br>Senha: <input type='password' name='senha' value='' size='16' style='height:20px;font-size:10px' />
                                        <input type='submit' value='Logar' style='height:20px;font-size:9px;text-align:center'/>";
                                echo " <div id='logoff'>";
                                echo "Esqueceu seu acesso <a href='GUI/RecuperaSenha.php'>Clique aqui!</a></font>";
                                echo"</table>";
                                echo"</form>";



                                ?>

                            <script language="JavaScript">

                                <!--
                                var d = new Date()
                                var h = d.getHours()

                                if (h < 12)
                                    document.write("Bom-dia ! ")
                                else
                                    if (h < 18)
                                        document.write("Boa-tarde ! ")
                                else
                                    document.write("Boa-noite ! ")
                                // -->
                            </script>

                                <?php
                                echo "</font<font color='yellow'><b>&nbsp;&nbsp;Visitante</b></font><br>";
                            }
                            if ($errologin==1) {

                                echo "<font color='red'>";

                                echo "<img src='/Esquina_da_TI/images/false.png' width='16' height='16' alt='false'/>&nbsp;<b>Usuario ou Senha Inválidos</b>";
                                echo "</font>";
                            }

                            echo "</div>";

                            ?>

                        </li>
                    </ul>
                        <a href="/Esquina_da_TI/index.php"><font color="blue">«Voltar</font></a>
                        <br><br>
                    </div>

                    <!--LINHA DO RODAPÉ-->
                    <div style="clear: both;">&nbsp;</div>
                </div>
            </div>

            <!--RODAPÉ-->
            <div id="footer">
                <p class="copyright">&copy;&nbsp;&nbsp;2009 All Rights Reserved &nbsp;&bull;&nbsp; Design by <a href="#">H1 Softwares</a>.</p>
                <p class="link"><a href="#">Privacy Policy</a>&nbsp;&#8226;&nbsp;<a href="#">Terms of Use</a></p>
            </div>
            <?php
            // put your code here
            ?>
        </center>
    </body>
</html>
